package com.hgd.igreencar.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo;
import com.hgd.igreencar.biz.IVehicleExhaustPlusBiz;
import com.hgd.igreencar.entity.VehicleExhaustPlus;
import com.hgd.igreencar.entity.WebsiteUsers;
import com.hgd.igreencar.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/VehicleExhaustPlus")
public class VehicleExhaustPlusController {

    @Autowired
    private IVehicleExhaustPlusBiz vehicleExhaustPlusBiz;
    /**
     * 查询所有的排放情况（不管是否超标）
     */
//    @GetMapping("/list")
//    public Result queryData(
//            @RequestParam(required = false,defaultValue = "上海")String areaName,
//            @RequestParam(required = false,defaultValue = "宝马")String brandName,
//            @RequestParam(required = false,defaultValue = "CO")String letoutName,
//            @RequestParam(required = false,defaultValue = "1")int currentPage,
//            @RequestParam(required = false,defaultValue = "10")int pageSize){
//        PageInfo<VehicleExhaustPlus> pageInfo = vehicleExhaustPlusBiz.queryData(areaName,brandName,letoutName,currentPage,pageSize);
//        return Result.ok(pageInfo);
//    }

    /**
     * 查询所有的排放情况（不管是否超标）
     */
    @GetMapping("/allList")
    public Result queryAllData(
            @RequestParam(required = false,defaultValue = "1")int currentPage,
            @RequestParam(required = false,defaultValue = "10")int pageSize){
        PageInfo<VehicleExhaustPlus> pageInfo = vehicleExhaustPlusBiz.queryAllData(currentPage,pageSize);
        return Result.ok(pageInfo);
    }
    /**
     * 按需查询所有的排放情况（以JSON形式传不管是否超标）
     */
    @PostMapping("/listByJson")
    public Result queryData(@RequestBody String dataJson){
        JSONObject jsonObject = JSON.parseObject(dataJson);
        String areaName = jsonObject.getString("areaName");
        String brandName = jsonObject.getString("brandName");
        String letoutName = jsonObject.getString("letoutName");
        Integer currentPage = jsonObject.getInteger("currentPage");
        Integer pageSize = jsonObject.getInteger("pageSize");
        PageInfo<VehicleExhaustPlus> pageInfo = vehicleExhaustPlusBiz.queryData(areaName,brandName,letoutName, currentPage,pageSize);
        return Result.ok(pageInfo);
    }

    /**
     * 查询超标的排放情况
     */
//    @GetMapping("/overlist")
//    public Result queryByOver(
//            @RequestParam(required = false,defaultValue = "上海")String areaName,
//            @RequestParam(required = false,defaultValue = "宝马")String brandName,
//            @RequestParam(required = false,defaultValue = "CO")String letoutName,
//            @RequestParam(required = false,defaultValue = "1")int currentPage,
//            @RequestParam(required = false,defaultValue = "10")int pageSize){
//
//        PageInfo<VehicleExhaustPlus> pageInfo = vehicleExhaustPlusBiz.queryByOver(areaName,brandName,letoutName,currentPage,pageSize);
//        return Result.ok(pageInfo);
//    }

    /**
     * 查询所有的超标排放情况
     */
    @GetMapping("/allOverList")
    public Result queryAllOverData(
            @RequestParam(required = false,defaultValue = "1")int currentPage,
            @RequestParam(required = false,defaultValue = "10")int pageSize){
        PageInfo<VehicleExhaustPlus> pageInfo = vehicleExhaustPlusBiz.queryAllOverData(currentPage,pageSize);
        return Result.ok(pageInfo);
    }

    /**
     * 按需查询所有的超标排放情况（以JSON形式传不管是否超标）
     */
    @PostMapping("/overListByJson")
    public Result queryByOver(@RequestBody String dataJson){
        JSONObject jsonObject = JSON.parseObject(dataJson);
        String areaName = jsonObject.getString("areaName");
        String brandName = jsonObject.getString("brandName");
        String letoutName = jsonObject.getString("letoutName");
        Integer currentPage = jsonObject.getInteger("currentPage");
        Integer pageSize = jsonObject.getInteger("pageSize");
        PageInfo<VehicleExhaustPlus> pageInfo = vehicleExhaustPlusBiz.queryByOver(areaName,brandName,letoutName, currentPage,pageSize);
        return Result.ok(pageInfo);
    }
}
